/**
 * Created by li_xiaoliang on 2015/4/18.
 */
//创建子进程去运行爬虫系统
var cp=require('child_process');
var Q=require('q');
var child_hupu=cp.fork('./middleware/hupuscrapy.js');

function param(name,option){
    this.name=name;
    this.option=option;
}

exports.hupuNBAnews= function () {
    var d= Q.defer();
    child_hupu.send(new param("hupuNews"));
    child_hupu.on('message', function (message) {
        if(!message&&message.newlist) {
            d.reject("no data!")
        }else {
            d.resolve(message.newlist);
        }
    });
    return d.promise;
}

exports.hupuNBAcontent=function(url){
    var d= Q.defer();
    child_hupu.send(new param("article",{url:url}));
    child_hupu.on('message', function (message) {
        if(!message&&message.article) {
            d.reject("no data!")
        }else {
            d.resolve(message.article);
        }
    });
    return d.promise;
}
